﻿using ProjectScheduling.daos;
using System.Data;

namespace ProjectScheduling
{
    public partial class WorkingHoursForm : Form
    {
        public readonly static WorkingHoursForm b = new();
        public void Init(int id)
        {

            var table = new DataTable();
            table.Columns.Add("StaffName");
            table.Columns.Add("FromDate");
            table.Columns.Add("ToDate");
            table.Columns.Add("Days");
            PreparedDataDao.Base.FindAll(it => it.ProjectId == id).
                        SelectMany(it => it?.PrepardStaffs?.
                                    Select(item => new { item?.Content?.StaffName, item?.Content?.FromDate, item?.Content?.ToDate, item?.Days }).ToList() ?? []).
                        ToList().
                        ForEach(it =>
                        {
                            var row = table.NewRow();
                            row["StaffName"] = it.StaffName;
                            row["FromDate"] = it.FromDate?.ToString("yyyy-MM-dd HH:00:00")??"";
                            row["ToDate"] = it.ToDate?.ToString("yyyy-MM-dd HH:00:00") ?? "";
                            row["Days"] = it.Days;
                            table.Rows.Add(row);
                        });
            view_all.DataSource = table;
            ShowDialog();
        }
        public WorkingHoursForm()
        {
            InitializeComponent();
            view_all.AutoGenerateColumns = false;
            view_all.AutoSizeRowsMode=DataGridViewAutoSizeRowsMode.AllCells;
        }

        private void View_All_SelectionChanged(object sender, EventArgs e)
        {
            view_all.ClearSelection();
        }
    }
}
